package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.constant.UserConstants;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Fans;
import com.ruoyi.system.service.IFansService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * fans信息管理表Controller
 * 
 * @author zyy
 * @date 2025-10-30
 */
@RestController
@RequestMapping("/system/fans")
public class FansController extends BaseController
{
    @Autowired
    private IFansService fansService;

    /**
     * 查询fans信息管理表列表
     */
    @PreAuthorize("@ss.hasPermi('system:fans:list')")
    @GetMapping("/list")
    public TableDataInfo list(Fans fans)
    {
        startPage();
        List<Fans> list = fansService.selectFansList(fans);
        return getDataTable(list);
    }

    /**
     * 导出fans信息管理表列表
     */
    @PreAuthorize("@ss.hasPermi('system:fans:export')")
    @Log(title = "fans信息管理表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Fans fans)
    {
        List<Fans> list = fansService.selectFansList(fans);
        ExcelUtil<Fans> util = new ExcelUtil<Fans>(Fans.class);
        util.exportExcel(response, list, "fans信息管理表数据");
    }

    /**
     * 获取fans信息管理表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:fans:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fansService.selectFansById(id));
    }

    /**
     * 新增fans信息管理表
     */
    @PreAuthorize("@ss.hasPermi('system:fans:add')")
    @Log(title = "fans信息管理表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Fans fans)
    {
        if(UserConstants.NOT_UNIQUE.equals(fansService.checkFansNameUnique(fans))){
            return AjaxResult.error("新增fans'" + fans.getFansName() + "'失败，昵称已存在");
        }

        return toAjax(fansService.insertFans(fans));
    }

    /**
     * 修改fans信息管理表
     */
    @PreAuthorize("@ss.hasPermi('system:fans:edit')")
    @Log(title = "fans信息管理表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Fans fans)
    {
        if(UserConstants.NOT_UNIQUE.equals(fansService.checkFansNameUnique(fans))){
            return AjaxResult.error("修改fans'" + fans.getFansName() + "'失败，昵称已存在");
        }
        return toAjax(fansService.updateFans(fans));
    }

    /**
     * 删除fans信息管理表
     */
    @PreAuthorize("@ss.hasPermi('system:fans:remove')")
    @Log(title = "fans信息管理表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fansService.deleteFansByIds(ids));
    }

    /**
     *  fans信息管理表提示信息
     */
    @PreAuthorize("@ss.hasPermi('system:fans:msg')")
    public AjaxResult msg()
    {
        return msg();
    }

}
